<template>
  <div class="page">
    <!-- 顶部栏 -->
    <van-nav-bar fixed placeholder :border="false">
      <template #title>
        <div class="fz-16 fw-bold">黄金商城</div>
      </template>

      <template #right>
        <div class="cl-white click" @click="router.push('/order/index')">
          兑换记录
        </div>
      </template>
    </van-nav-bar>

    <div class="container">
      <!-- 商品列表 -->
      <ul v-if="products.length">
        <li
          class="opacity radius flex flex-cc cl-white mb-10"
          v-for="(v, i) in products"
          :key="i"
          @click="router.push(`/product/detail?id=${v.id}`)"
        >
          <img
            class="opacity radius"
            style="width: 133px; height: 121px"
            :src="v.coverImg"
          />

          <div class="p-10">
            <div class="mb-10">
              <div class="fz-18 fw-bold">{{ v.name }}</div>
              <div class="price">{{ v.price }}克</div>
              <div class="fz-12">手工费：{{ v.fees }}</div>
            </div>

            <div class="fz-12">剩余：{{ v.stock }}件</div>
          </div>
        </li>
      </ul>

      <!-- 暂无数据 -->
      <van-empty v-else>
        <span class="cl-white">暂无数据</span>
      </van-empty>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import goldApi from 'js/gold.api'

const router = useRouter()
const products = ref([])

getProductList()

async function getProductList() {
  const params = {
    current: 1,
    size: 100000,
  }

  const { code, data } = await goldApi.getProductList(params)

  if (code === 200) {
    products.value = data.records || []
  }
}
</script>

<style lang="scss" scoped></style>
